package ysq.xyg.web.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.web.model.po.WebShare;
import ysq.xyg.web.model.vo.WebShareVo;
import ysq.xyg.web.service.WebShareService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 业务模块-微信分享controller层
 *
 * @author shengQiang yu
 * @date 2019-5-17 10:29:41
 */
@RestController
public class WebShareController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebShareController.class);
    @Resource
    private WebShareService webShareService;

    private WebShare webShare;

    /**
     * 分页查询
     *
     * @param webShareVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-5-17 10:29:41
     */
    @BaseLog(module = "业务模块",className = "微信分享",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webShare/page",method = RequestMethod.POST)
    public ReturnEntity page(WebShareVo webShareVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webShareService.page(webShareVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-17 10:29:41
     */
    @RequestMapping(value = "/webShare/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webShareUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webShare = webShareService.selectByPrimaryKey(id);
            view.addObject("webShare", webShare);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-17 10:29:41
     */
    @BaseLog(module = "业务模块",className = "微信分享",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webShare/delete")
    public ReturnEntity delete(HttpServletRequest request, String id){
        return webShareService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webShareVo Vo对象
     * @author shengQiang yu
     * @date 2019-5-17 10:29:41
     */
    @BaseLog(module = "业务模块",className = "微信分享",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webShare/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request, WebShareVo webShareVo){
        return webShareService.addOrUpdate(webShareVo,acceptCurrentUser(request));
    }
}